chdkfandomcom-20200222-history
PTP Extension
The Picture Transfer Protocol (PTP) facilitates remote operations on a camera connected computer. Typical operations are uploading/downloading photos and remote captures. Most cameras support some basic operations over PTP, but often only in a limited fashion. For example, downloading of files can be limited to just JPEG files. The PTP extension for CHDK discussed in this article is does not alter the standard operations but adds new CHDK-specific operations instead. This is due to the complexity involved in altering or complete overwriting the standard operations. It also means that special tools are required to access this new functionality. The CHDK extension was first added to the CHDK trunk in changeset 957, and has been enabled for all cameras since changeset 1116 Related forum thread: http://chdk.setepontos.com/index.php/topic,4338.0.html Functionality An overview of the functionality available through the PTP interface is described below. The specific functionality and usage depends on which client application you use. The canonical reference to the CHDK PTP protocol is core/ptp.h in the CHDK source tree. File transfer Files can be uploaded to and downloaded from any part of the file system. Script execution The PTP interface allows execution of lua scripts sent over PTP. In general, any scripting function available to normal CHDK scripts can be executed remotely. There are some additional functions specific to PTP, described in Lua/PTP Scripting. Some of the features available using Lua scripts include * Switch to and from record mode * Switch recording modes, e.g. Av, Tv, Video * Adjust exposure parameters, focus, zoom etc. * Shoot pictures or video * Manipulate Canon menus and settings with simulated key presses * List, create and delete files and directories * Return values from script, send and receive arbitrary messages between the camera and PC * Shutdown or reboot the camera Remote display In CHDK 1.1 (currently under development) support has been added for streaming the contents of the camera LCD display over PTP. (revision 1921 and later) Debugging features * Read and write camera memory * call arbitrary camera functions LibUSB driver for windows All the client applications below require libusb-win32 driver on windows. Available for Windows 2000, Windows XP 32 Bit, Windows Vista 32/64 Bit, Windows 7 32/64 Bit. 1. Extract archive. 2. Connect camera via USB and turn on in play mode. 3. Search in extracted archive in subdirectory for inf_wizard.exe and run this file. 4. Select in the second window 'Device Selection' your camera. 5. The driver will be provided and installed. 6. No PC reboot is needed. Client applications As described above, a client program compatible that implements the CHDK protocol is required to access these features ptpcam : If you are new to ptpcam check out ptpcamgui below. More advanced users may wish to use ptpcam. : Download: ::: 1) download and install libusb (see instructions in English translation found in ptpcamgui below) ::: 2) go here (German CHDK forum topic) ::: 3) download ptpcam_Vx.x.zip at the end of the first message. : Note that PTP is simply a protocol for communicating with your camera and is available for cameras other than Canon. The version of ptpcam available in the forum link has CHDK extensions added. This is a derivative of the opensource ptpcam available at http://libptp.sourceforge.net/ (this source code doesn't include CHDK extensions, also note: no compiled executable is available at the sourceforge link). : If you are comfortable writing batch scripts (or perl/python/... scripts) ptpcam can be used to download jpg files and upload lua scripts and execute lua scripts all while your camera is mounted to a tripod (when, for most Canon cameras, removing the memory card is not possible). : Keep in mind the fact that scripts or LUA commands executed on the camera will take more time to complete than it takes for ptpcam to return control to your script. So make sure that after you issue a shoot command or run a LUA script on the camera, that you have a delay in your (batch file, perl, ...) script running on your PC to give the camera time to finish its business before poking the camera again. C:\ptpcam_V2.0>ptpcam -h USAGE: ptpcam OPTION Options: --bus=BUS-NUMBER USB bus number --dev=DEV-NUMBER USB assigned device number -r, --reset Reset the device -l, --list-devices List all PTP devices -i, --info Show device info -o, --list-operations List supported operations -p, --list-properties List all PTP device properties (e.g. focus mode, focus distance, etc.) -s, --show-property=NUMBER Display property details (or set its value, if used in conjunction with --val) --set-property=NUMBER Set property value (--val required) --set=PROP-NAME Set property by name (abbreviations allowed) --val=VALUE Property value (numeric for --set-property and string or numeric for --set) --show-all-properties Show all properties values --show-unknown-properties Show unknown properties values -L, --list-files List all files -g, --get-file=HANDLE Get file by given handler -G, --get-all-files Get all files --overwrite Force file overwrite while savingto disk -d, --delete-object=HANDLE Delete object (file) by given handle -D, --delete-all-files Delete all files form camera -c, --capture Initiate capture --nikon-ic, --nic Initiate Nikon Direct Capture (no download!) --nikon-dc, --ndc Initiate Nikon Direct Capture and download --loop-capture=N Perform N times capture/get/delete -f, --force Talk to non PTP devices -v, --verbose Be verbose (print more debug) -h, --help Print this help message --chdk=command CHDK mode. Interactive shell unless optional command is given. Run interactive shell and press 'h' for a list of commands. : The original source as well as the proposal consist of both a patch for the SVN trunk and a patch for the ptpcam program. The latter adds an option --chdk with starts an interactive prompt to communicate with the connected camera. : A version of ptpcam is maintained in the chdkde source tree, with builds available from the chdkde forum (download ptpcam_Vx.x.zip). : ptpcam may be built for Windows or Linux. ptpCamGui : As of June 2012, most will likely want to start using PTP with this program (at least until chdkptp is out of alpha). : ptpCamGui is a graphical front end for ptpcam. Builds are available from the chdkde forum It's also part of CHDK Shell. : A forum thread including descriptions can you find here. : The source code for the frontend and the DLL is available on the ptpCamGui assembla project. : ptpCamGui is only available for Windows. : English translation of instructions for using can be found here. Note that despite coming from a German site, both English and German languages are supported in the same .exe and are set automatically (based on your Windows installation language setting). : First time users note that the big red camera icon is used both to enter camera mode and to shoot (when radio buttons to right select "Photo"). chdkptp An under development client. Considered pre-alpha because functionality and APIs are subject to change. However, the snapshot builds are usable for most common operations. CHDK 1.1 remote display is supported. Source and builds can be found on the chdkptp assembla project. A thread in the chdk forum is available for discussion. chdkptp provides a lua API to the CHDK protocol on the PC. A CLI and optional GUI based on IUP are implemented in Lua. This allows easy customization, and enables end users to quickly implement complex interactions with code on the camera. chdkptp is compatible with windows and linux. chdkcam (historical) CHDKCAM is a Windows program that provides a graphical interface to the camera and also allows live streaming of the camera's screen. The CHDKCAM binaries should also be compatible with the adapted ptpcam from the original source. CHDKCAM is only compatible with early development versions of the protocol, it is not compatible with the current CHDK or CHDKDE builds. Usage notes Windows In order to get CHDKCAM or ptpcam to work properly you might need to disable the "Canon Camera Access Library" service (or, if that doesn't work, the "WIA" service). Linux Make sure you've got access to USB; in some cases this means switching to root (or changing permissions). Development details Also see the original documentation and the forum thread. FAQ * Download/upload fails with code 0x2ff or the camera crashes when you try to transfer a file :: Perhaps you didn't correctly specify the file on the camera. Always use the full path and start with a capitalised 'A'. For example: "download A/DCIM/100CANON/IMG_1234.jpg test.jpg" ::note this mainly applies to ptpcam, chdkptp corrects the names for you. * The canon firmware does not recognize key presses (real or from script) when PTP is connected :There are two known workarounds: :* Switch to record mode using switch_mode_usb script function. Keys will still be enabled if you switch back to play. :* On many DryOS cameras, post_levent_to_ui(4484) will also unlock the keys. Adding support for another camera/firmware version (historical) note the following is for historical reference only. PTP is implemented in all complete CHDK ports now. As with CHDK itself it is usually a good idea to base your efforts on the sources of a similar camera. The essential steps to get any CHDK PTP support are as follows. * Find the add_ptp_handler function for your firmware. * Make sure init_chdk_ptp is started as a task. This should enable you to connect with ptpcam --chdk and download/upload files, read/write memory and execute remote functions as well as Lua code. Next you probably want to find a way to switch the camera to record mode (and back to playback mode). How to do this depends on the camera, so you probably need to check your reference source for this. Finally you might want to add specific functions like those needed for CHDKCAM. Functionality Comparison (historical) The various variants (original source, CHDKCAM, proposal for addition to trunk) of the CHDK PTP extension support the following functionality. L=functionality available using Lua 1 script error messages are returned and scripts can send arbitrary data, but console output is not returned. Note that the proposal has much less extensions as the idea is to keep CHDK PTP as small as possible and provide the rest of the functionality (e.g. mode switching, shutdown/reboot) via scripting. Availability (historical versions) The proposal version, with some minor modifications, has been included in CHDK trunk since changeset 957 At mweerden's github one can find the original sources as well as a follow-up attempt at a minimal version for inclusion in the SVN trunk. At ewavr's site you can find his CHDKCAM program and binaries for various firmwares. Below is an overview of the currently supported firmwares. Here "cc" means there is a CHDKCAM version, "mg" it's supported in mweerden's code, "(b)" that there is a binary, "(s)" that it's in the source and "(p)" that there is a patch. Category:Development Category:PTP Extension